package com.test.controller;

import java.io.IOException;
import java.io.OutputStream;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.test.common.FileUtil;
import com.test.dao.UserDao;
import com.test.model.WriteModel;

@Controller
@RequestMapping("/file")
public class exportController {
	
	@Resource
	private UserDao userDao;
	@RequestMapping("/export")
	public void export(HttpServletRequest request ,HttpServletResponse response) throws IOException{
		OutputStream outputStream = response.getOutputStream();
		List<WriteModel> list = userDao.getAllUser();
		FileUtil.esportFile(outputStream, list);
		response.setContentType("multipart/form-data");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Content-disposition", "attachment;filename="+System.currentTimeMillis()+".xls");
		outputStream.flush();
	}
}
